<template>
  <div>
    <div id="slider" class="mui-slider">
      <div
        id="sliderSegmentedControl"
        class="
          mui-scroll-wrapper
          mui-slider-indicator
          mui-segmented-control
          mui-segmented-control-inverted
        "
      >
        <div class="mui-scroll">
          <a
            :class="[
              'mui-control-item',
              item.user_id === 0 ? 'mui-active' : '',
            ]"
            v-for="item in cases"
            :key="item.user_id"
            @click="getallpostos(item.user_id)"
          >
            {{ item.name }}
          </a>
        </div>
      </div>
    </div>

    <ul class="post-list">
      <router-link
        :to="'/home/photolist/potoinfo/' + (i + 1)"
        tag="li"
        v-for="(item, i) in list"
        :key="item.url"
      >
        <img v-lazy="item.url" />

        <div class="info-content">
          <h1 class="info-title">MGS{{ i + 1 }}</h1>
          <div class="info-body">{{ item.createdAt | dataformat }}</div>
        </div>
      </router-link>
    </ul>
  </div>
</template>

<script>
import mui from "../assets/js/mui.min.js";

export default {
  data() {
    return {
      cases: [
        {
          name: "随机",
          user_id: 0,
        },
        {
          name: "第一页",
          user_id: 1,
        },
        {
          name: "第二页",
          user_id: 2,
        },
        {
          name: "第三页",
          user_id: 3,
        },
        {
          name: "第四页",
          user_id: 4,
        },
        {
          name: "第五页",
          user_id: 5,
        },
      ],
      list: [],
    };
  },

  created() {
    this.getallpostos(0);
  },

  //scroll水平横向滚动条
  mounted() {
    mui(".mui-scroll-wrapper").scroll({
      deceleration: 0.0005,
    });
  },

  methods: {
    getallpostos(listid) {
      this.$http
        .get("https://www.apiopen.top/meituApi?page=" + listid)
        .then((res) => {
          if (res.status === 200) {
            this.list = res.body.data;
          }
        });
    },
  },
};
</script>

<style lang="less" scoped>
* {
  touch-action: pan-y;
}

.mui-segmented-control.mui-scroll-wrapper .mui-scroll {
  line-height: 40px;
}

.post-list {
  padding: 10px;
  li {
    width: 100%;
    padding: 0;
    text-align: center;
    margin-bottom: 25px;
    list-style: none;
    background-color: #ccc;
    position: relative;

    img[lazy="loading"] {
      width: 40px;
      height: 300px;
      margin: auto;
    }
    img {
      width: 100%;
      vertical-align: middle;
    }
    .info-content {
      text-align: start;
      position: absolute;
      left: 5px;
      bottom: 0;
      color: #fff;
      .info-title {
        font-size: 12px;
        margin: 0;
      }
      .info-body {
        font-size: 10px;
        margin: 0;
      }
    }
  }
}
</style>
